﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Eb.StockManagement;
using Eb.MessageBox;

public partial class Modules_StockManagement_ProcureHistory : System.Web.UI.UserControl
{
    #region Fields
    StockManagement stockManagement = new StockManagement();
    SearchCriteria advanceSearch = new SearchCriteria();
    LocalSearchCriteria locAdvanceSearch = new LocalSearchCriteria();
    DepartmentSearchCriteria deptSearchCriteria = new DepartmentSearchCriteria();
    DataSet ds = new DataSet();
    DataSet localDS = new DataSet();
    DataSet deptDS = new DataSet();
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PopulateDepartmentMoveGrid();
            PopulateProcureHistoryGrid();
            PopulateLocalPurchase();
            ddlSelect.Items.Add("Between");
            ddlSelect.Items.Add("<=");
            ddlSelect.Items.Add(">=");
            ddlSelect.Items.Add("=");
            ddlSelect.Items.Insert(0, "-Select-");

            ddlSelect1.Items.Add("Between");
            ddlSelect1.Items.Add("<=");
            ddlSelect1.Items.Add(">=");
            ddlSelect1.Items.Add("=");
            ddlSelect1.Items.Insert(0, "-Select-");

            ddlAmountSelect.Items.Add("<=");
            ddlAmountSelect.Items.Add(">=");
            ddlAmountSelect.Items.Add("=");
            ddlAmountSelect.Items.Insert(0, "-Select-");

            ddlSelect3.Items.Add("Between");
            ddlSelect3.Items.Add("<=");
            ddlSelect3.Items.Add(">=");
            ddlSelect3.Items.Add("=");
            ddlSelect3.Items.Insert(0, "-Select-");

            
        }
    }
    protected void TabContainer1_ActiveTabChanged(object sender, EventArgs e)
    {


    }
    void PopulateDepartmentMoveGrid()
    {
        bool status = stockManagement.SearchDepartmentMoveProcure(deptSearchCriteria, out deptDS);
        grvDepartmentMove.DataSource = deptDS;
        grvDepartmentMove.DataBind();
    }
    void PopulateLocalPurchase()
    {
        bool status = stockManagement.SearchLocalPurchaseProcure(locAdvanceSearch, out localDS);
        grvLocalPurchaseMaster.DataSource = localDS;
        grvLocalPurchaseMaster.DataBind();
    }
    void PopulateProcureHistoryGrid()
    {
        try
        {
            bool res = stockManagement.SearchProcureList(advanceSearch, out ds);
            grvBatchHistory.DataSource = ds;
            grvBatchHistory.DataBind();
            //DataSet procureHistoryDS = new DataSet();
            //procureHistoryDS = stockManagement.GetProcureHistory();
            //grvBatchHistory.DataSource = procureHistoryDS;
            //grvBatchHistory.DataBind();
        }
        catch (Exception exp)
        {
            Session["ERRTITLE"] = "Failed to Populate ProcureHistory!";
            Session["ERRDET"] = exp.Message;
            Response.Redirect("ErrorPage.aspx");
        }
    }
    protected void grvLocalPurchaseMaster_RowDataBound(object sender, GridViewRowEventArgs e)
    {
         #region Fields
        int purchaseID = 0;
        DataSet stockDetailsDS = new DataSet();
        #endregion

        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                GridView gv = (GridView)e.Row.FindControl("grvLocalPurchaseDetails");
                string lbllocalPurchaseID = ((Label)e.Row.FindControl("lblPurchaseID")).Text;
                if (lbllocalPurchaseID != "")
                    purchaseID = Convert.ToInt16(lbllocalPurchaseID);
                stockDetailsDS = stockManagement.GetLocalPurchaseDetailsByPurchaseID(purchaseID);
                gv.DataSource = stockDetailsDS;
                gv.DataBind();
            }
        }
        catch (Exception exp)
        {
            Session["ERRTITLE"] = "Failed to retrive LocalPurchase !";
            Session["ERRDET"] = exp.Message;
            Response.Redirect("ErrorPage.aspx");
        }
    }
    protected void grvBatchHistory_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        #region NameSpace
        int lotId = 0;
        DataSet stockDetailsDS = new DataSet();
        #endregion

        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                GridView gv = (GridView)e.Row.FindControl("grvProductMovement");
                string lblLotId = ((Label)e.Row.FindControl("lblLotID")).Text;
                if (lblLotId != "")
                    lotId = Convert.ToInt16(lblLotId);
                string purchaseType = ((Label)e.Row.FindControl("lblPurType")).Text;
                if (purchaseType == "General")
                {
                    stockDetailsDS = stockManagement.GeneralProcureHistory(lotId);
                    gv.DataSource = stockDetailsDS;
                    gv.DataBind();
                }
                else
                {
                    stockDetailsDS = stockManagement.GetProductionWiseProcureHistory(lotId);
                    gv.DataSource = stockDetailsDS;
                    gv.DataBind();

                }


            }
        }
        catch (Exception exp)
        {
            Session["ERRTITLE"] = "Failed to retrive purchaseOrderID !";
            Session["ERRDET"] = exp.Message;
            Response.Redirect("ErrorPage.aspx");
        }
    }
    protected void ddlSelect1_SelectedIndexChanged(object sender, EventArgs e)
    {
        ImageButton3.Enabled = true; ;
        ddlSelect1.Enabled = true;
        txtDateOfCreation.Enabled = true;
        txtLocalPurchasRequester.Enabled = false;
        txtAmount.Enabled = false;
       txtDate1.Text = string.Empty;
       txtDate1.Enabled = false;
       if (ddlSelect1.SelectedItem.ToString() == "Between")
       {
           ImageButton4.Enabled = true; ;
           txtDate1.Enabled = true;
           locAdvanceSearch.DateofCreation1 = txtDate1.Text.Trim();
       }
       else
       {
           locAdvanceSearch.DateofCreation = txtDateOfCreation.Text.Trim();
           locAdvanceSearch.Requester = string.Empty;
           locAdvanceSearch.ApproximateMount = 0;
           if (ddlSelect1.SelectedIndex != 0)
               locAdvanceSearch.DateStatus = ddlSelect1.SelectedItem.ToString();
           else
               locAdvanceSearch.DateStatus = "0";
       }
    }
    protected void ddlSelect3_SelectedIndexChanged(object sender, EventArgs e)
    {
        ImageButton5.Enabled = true;
        ddlSelect3.Enabled = true;
        txtDateOfCreation2.Enabled = true;
        txtDeptProductCode.Enabled = false;
        txtDeptProductName.Enabled = false;
        txtDeptMovedBy.Enabled = false;
        if (ddlSelect3.SelectedItem.ToString() == "Between")
        {
            ImageButton6.Enabled = true; ;
            txtDate2.Enabled = true;
            deptSearchCriteria.DateofCreation1 = txtDate2.Text.Trim();
        }
        else
        {

            deptSearchCriteria.DateofCreation = txtDateOfCreation.Text.Trim();
            deptSearchCriteria.ProductCode = string.Empty;
            deptSearchCriteria.ProductName = string.Empty;
            deptSearchCriteria.MovedBy = string.Empty;
            if (ddlSelect3.SelectedIndex != 0)
                deptSearchCriteria.DateStatus = ddlSelect3.SelectedItem.ToString();
            else
                deptSearchCriteria.DateStatus = "0";
        }

    }
    protected void ddlSelect_SelectedIndexChanged(object sender, EventArgs e)
    {
        ImageButton1.Enabled = true; ;
        ddlSelect.Enabled = true;
        txtDateOfCreation.Enabled = true;
        txtProductName.Enabled = false;
        txtPurchaseOrderID.Enabled = false;
        advanceSearch.ProductName = string.Empty;
        txtDate.Text = string.Empty;
        txtDate.Enabled = false;
        if (ddlSelect.SelectedItem.ToString() == "Between")
        {
            ImageButton2.Enabled = true; ;
            txtDate.Enabled = true;
            advanceSearch.DateofCreation1 = txtDate.Text.Trim();
        }
        else
        {

            advanceSearch.DateofCreation = txtDateOfCreation.Text.Trim();
            advanceSearch.PurchaseOrderID = string.Empty;
            advanceSearch.ProductName = string.Empty;
            if (ddlSelect.SelectedIndex != 0)
                advanceSearch.DateStatus = ddlSelect.SelectedItem.ToString();
            else
                advanceSearch.DateStatus = "0";
        }
    }
    protected void btnSearch1_Click(object sender, EventArgs e)
    {
        if (rbLocalPurchase.SelectedItem != null)
        {
            LocalAdvancedSerch();
        }
        PopulateLocalPurchase();
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        if (rblCriteria.SelectedItem != null)
        {
            AdvancedSerch();
        }
        bool res = stockManagement.SearchProcureList(advanceSearch, out ds);
        grvBatchHistory.DataSource = ds;
        grvBatchHistory.DataBind();
    }
    protected void DepartmentProcureHistoryAdvanceSearch()
    {
        if (rbDepartmentMove.SelectedItem.ToString() == "ProductCode")
        {
            txtDeptProductCode.Enabled = true;
            txtDeptProductName.Enabled = false;
            txtDeptProductName.Text = string.Empty;
            txtDeptMovedBy.Enabled = false;
            txtDeptMovedBy.Text = string.Empty;
            ddlSelect3.SelectedIndex = 0;
            txtDateOfCreation2.Text = string.Empty;
            txtDateOfCreation2.Enabled = false;
            txtDate2.Text = string.Empty;
            txtDate2.Enabled = false;
            deptSearchCriteria.ProductCode = txtDeptProductCode.Text.Trim();
            deptSearchCriteria.ProductName = string.Empty;
            deptSearchCriteria.MovedBy = string.Empty;
            deptSearchCriteria.DateofCreation = string.Empty;
            deptSearchCriteria.DateofCreation1 = string.Empty;
            deptSearchCriteria.DateStatus = "0";
        }
        else if (rbDepartmentMove.SelectedItem.ToString() == "ProductName")
        {
            txtDeptProductCode.Enabled = false;
            txtDeptProductName.Enabled = true;
            txtDeptProductCode.Text = string.Empty;
            txtDeptMovedBy.Enabled = false;
            txtDeptMovedBy.Text = string.Empty;
            ddlSelect3.SelectedIndex = 0;
            txtDateOfCreation2.Text = string.Empty;
            txtDateOfCreation2.Enabled = false;
            txtDate2.Text = string.Empty;
            txtDate2.Enabled = false;
            deptSearchCriteria.ProductCode = string.Empty;
            deptSearchCriteria.ProductName = txtDeptProductName.Text.Trim();
            deptSearchCriteria.MovedBy = string.Empty;
            deptSearchCriteria.DateofCreation = string.Empty;
            deptSearchCriteria.DateofCreation1 = string.Empty;
            deptSearchCriteria.DateStatus = "0";

        }
        else if (rbDepartmentMove.SelectedItem.ToString() == "MovedBy")
        {
            txtDeptProductCode.Enabled = false;
            txtDeptProductName.Enabled = false;
            txtDeptProductCode.Text = string.Empty;
            txtDeptMovedBy.Enabled = true;
            txtDeptProductName.Text = string.Empty;
            ddlSelect3.SelectedIndex = 0;
            txtDateOfCreation2.Text = string.Empty;
            txtDateOfCreation2.Enabled = false;
            txtDate2.Text = string.Empty;
            txtDate2.Enabled = false;
            deptSearchCriteria.ProductCode = string.Empty;
            deptSearchCriteria.ProductName = string.Empty;
            deptSearchCriteria.MovedBy = txtDeptMovedBy.Text.Trim();
            deptSearchCriteria.DateofCreation = string.Empty;
            deptSearchCriteria.DateofCreation1 = string.Empty;
            deptSearchCriteria.DateStatus = "0";

        }
        else if (rbDepartmentMove.SelectedItem.ToString() == "Date")
        {
            txtDateOfCreation2.Enabled = true;
            ddlSelect3.Enabled = true;
            ImageButton5.Enabled = true; ;
            txtDate2.Text = string.Empty;
            txtDate2.Enabled = false;
            txtDeptMovedBy.Text = string.Empty;
            txtDeptMovedBy.Enabled = false;
            txtDeptProductCode.Text = string.Empty;
            txtDeptProductCode.Enabled = false;
            txtDeptProductName.Enabled = false;
            txtDeptProductName.Text = string.Empty;
            deptSearchCriteria.DateofCreation = txtDate2.Text.Trim();
            deptSearchCriteria.DateofCreation1 = txtDateOfCreation2.Text.Trim();

            if (ddlSelect3.SelectedItem.ToString() == "Between")
            {

                ImageButton6.Enabled = true; ;
                txtDate2.Enabled = true;
                if (ddlSelect3.SelectedIndex != 0)
                    deptSearchCriteria.DateStatus = ddlSelect3.SelectedItem.ToString();
                else
                    deptSearchCriteria.DateStatus = "0";
            }
            else
            {
                deptSearchCriteria.ProductName = string.Empty;
                deptSearchCriteria.ProductCode = string.Empty;
                deptSearchCriteria.MovedBy = string.Empty;
                ImageButton6.Enabled = false; ;
                txtDate2.Enabled = false;
                if (ddlSelect3.SelectedIndex != 0)
                    deptSearchCriteria.DateStatus = ddlSelect3.SelectedItem.ToString();
                else
                    deptSearchCriteria.DateStatus = "0";
            }
        }
        else
        {
            txtDeptProductName.Text = string.Empty;
            txtDeptProductCode.Enabled = false;
            txtDeptProductName.Enabled = false;
            txtDeptProductCode.Text = string.Empty;
            txtDeptMovedBy.Enabled = false;
            txtDeptMovedBy.Text = string.Empty;
            ddlSelect3.SelectedIndex = 0;
            txtDateOfCreation2.Text = string.Empty;
            txtDateOfCreation2.Enabled = false;
            txtDate2.Text = string.Empty;
            txtDate2.Enabled = false;
        }
    }
    protected void LocalAdvancedSerch()
    {
        if (rbLocalPurchase.SelectedItem.ToString() == "Requester")
        {
            txtLocalPurchasRequester.Enabled = true;
            ddlAmountSelect.SelectedIndex = 0;
            ddlAmountSelect.Enabled = false;
            txtDateofCreation1.Text = string.Empty;
            txtDateofCreation1.Enabled = false;
            txtDate1.Text = string.Empty;
            txtDate1.Enabled = false;
            ddlSelect1.SelectedIndex = 0;
            txtAmount.Enabled = false;
            txtAmount.Text = string.Empty;
            locAdvanceSearch.Requester = txtLocalPurchasRequester.Text.Trim();
            locAdvanceSearch.DateofCreation = string.Empty;
            locAdvanceSearch.DateofCreation1 = string.Empty;
            locAdvanceSearch.ApproximateMount = 0;
            locAdvanceSearch.DateStatus = "0";

        }
        else if (rbLocalPurchase.SelectedItem.ToString() == "Amount")
        {
            if (ddlAmountSelect.SelectedIndex != 0)
            {
                lblLocalError.Visible = false;
                lblLocalError.Text = string.Empty;
                txtLocalPurchasRequester.Text = string.Empty;
                txtLocalPurchasRequester.Enabled = false;
                ddlAmountSelect.Enabled = true;
                txtAmount.Enabled = true;
                txtDateofCreation1.Text = string.Empty;
                txtDateofCreation1.Enabled = false;
                txtDate1.Text = string.Empty;
                txtDate1.Enabled = false;
                ddlSelect1.SelectedIndex = 0;
                if (txtAmount.Text.Trim() != null || txtAmount.Text.Trim() != "")
                    locAdvanceSearch.ApproximateMount = Convert.ToDouble(txtAmount.Text.Trim());
                if (ddlAmountSelect.SelectedIndex != 0)
                    locAdvanceSearch.AmountSelectStatus = ddlAmountSelect.SelectedItem.Text;
                locAdvanceSearch.Requester = string.Empty;
                locAdvanceSearch.DateofCreation = string.Empty;
                locAdvanceSearch.DateofCreation1 = string.Empty;
                locAdvanceSearch.DateStatus = "0";
            }
            else
            {
                lblLocalError.Visible = true;
                lblLocalError.Text="Pease select the criteria";
            }

        }
        else if (rbLocalPurchase.SelectedItem.ToString() == "Date")
        {

            txtDateofCreation1.Enabled = true;
            ddlSelect1.Enabled = true;
            ImageButton3.Enabled = true; ;
            txtDate1.Text = string.Empty;
            txtDate1.Enabled = false;
            txtLocalPurchasRequester.Text = string.Empty;
            txtLocalPurchasRequester.Enabled = false;
            txtDate1.Text = string.Empty;
            txtDate1.Enabled = false;
            ddlAmountSelect.SelectedIndex = 0;
            ddlAmountSelect.Enabled = false;
            txtAmount.Text = string.Empty;
            txtAmount.Enabled = false;
            locAdvanceSearch.DateofCreation = txtDate1.Text.Trim();
            locAdvanceSearch.DateofCreation1 = txtDateofCreation1.Text.Trim();
            
            if (ddlSelect1.SelectedItem.ToString() == "Between")
            {
                ImageButton4.Enabled = true; ;
                txtDate1.Enabled = true;
                if (ddlSelect1.SelectedIndex != 0)
                    locAdvanceSearch.DateStatus = ddlSelect.SelectedItem.ToString();
                else
                    locAdvanceSearch.DateStatus = "0";
            }
            else
            {
                locAdvanceSearch.Requester = string.Empty;
                locAdvanceSearch.ApproximateMount = 0;

                ImageButton4.Enabled = false; ;
                txtDate1.Enabled = false;
                locAdvanceSearch.DateofCreation = txtDateofCreation1.Text.Trim();
                if (ddlSelect1.SelectedIndex != 0)

                    locAdvanceSearch.DateStatus = ddlSelect1.SelectedItem.ToString();
                else
                    locAdvanceSearch.DateStatus = "0";
            }
        }
        else
        {
            ddlAmountSelect.SelectedIndex = 0;
            txtLocalPurchasRequester.Text = string.Empty;
            txtLocalPurchasRequester.Enabled = false;
            ddlAmountSelect.Enabled = false;
            txtAmount.Enabled = false;
            txtDateofCreation1.Text = string.Empty;
            txtDateofCreation1.Enabled = false;
            txtDate1.Text = string.Empty;
            txtDate1.Enabled = false;
            ddlSelect1.SelectedIndex = 0;
            txtAmount.Text = string.Empty;

        }
    }
    protected void AdvancedSerch()
    {

        if (rblCriteria.SelectedItem.ToString() == "PurchaseOrderID")
        {
            txtPurchaseOrderID.Enabled = true;
            txtDateOfCreation.Text = string.Empty;
            ddlSelect.SelectedIndex = 0;
            txtDate.Text = string.Empty;
            txtProductName.Text = string.Empty;
            txtProductName.Enabled = false;
            txtDate.Enabled = false;
            txtDateOfCreation.Enabled = false;
            ddlSelect.Enabled = false;
            advanceSearch.PurchaseOrderID = txtPurchaseOrderID.Text.Trim();
            advanceSearch.DateofCreation = string.Empty;
            advanceSearch.ProductName = string.Empty;
            advanceSearch.DateofCreation1 = string.Empty;
            advanceSearch.DateStatus = "0";

        }

        else if (rblCriteria.SelectedItem.ToString() == "ProductName")
        {
            txtProductName.Enabled = true;
            txtPurchaseOrderID.Text = string.Empty;
            txtDate.Text = string.Empty;
            txtDateOfCreation.Text = string.Empty;
            txtDate.Enabled = false;
            txtDateOfCreation.Enabled = false;
            ddlSelect.Enabled = false;
            txtPurchaseOrderID.Enabled = false;
            ddlSelect.SelectedIndex = 0;
            advanceSearch.PurchaseOrderID = string.Empty;
            advanceSearch.DateofCreation = string.Empty;
            advanceSearch.ProductName = txtProductName.Text.Trim();
            advanceSearch.DateofCreation1 = string.Empty;
            advanceSearch.DateStatus = "0";
        }
        else if (rblCriteria.SelectedItem.ToString() == "Date")
        {
            txtPurchaseOrderID.Text = string.Empty;
            txtProductName.Text = string.Empty;
            txtProductName.Enabled = false;
            ImageButton1.Enabled = true; ;
            ddlSelect.Enabled = true;
            txtDateOfCreation.Enabled = true;
            txtProductName.Enabled = false;
            txtPurchaseOrderID.Enabled = false;
            if (ddlSelect.SelectedItem.ToString() == "Between")
            {
                ImageButton2.Enabled = true; ;
                txtDate.Enabled = true;
                advanceSearch.DateofCreation = txtDateOfCreation.Text.Trim();
                advanceSearch.DateofCreation1 = txtDate.Text.Trim();
                advanceSearch.PurchaseOrderID = string.Empty;
                advanceSearch.ProductName = string.Empty;
                if (ddlSelect.SelectedIndex != 0)
                    advanceSearch.DateStatus = ddlSelect.SelectedItem.ToString();
                else
                    advanceSearch.DateStatus = "0";
            }
            else
            {

              
                advanceSearch.PurchaseOrderID = string.Empty;
                advanceSearch.ProductName = string.Empty;
                advanceSearch.DateofCreation = txtDateOfCreation.Text.Trim();
                if (ddlSelect.SelectedIndex != 0)

                    advanceSearch.DateStatus = ddlSelect.SelectedItem.ToString();
                else
                    advanceSearch.DateStatus = "0";
            }
        }
        else
        {
            txtDate.Enabled = false;
            txtDateOfCreation.Text = string.Empty;
            txtProductName.Text = string.Empty;
            txtPurchaseOrderID.Text = string.Empty;
            txtDateOfCreation.Enabled = false;
            txtProductName.Enabled = false;
            txtPurchaseOrderID.Enabled = false;
            advanceSearch.ProductName = string.Empty;
            advanceSearch.DateofCreation = string.Empty;
            advanceSearch.PurchaseOrderID = string.Empty;
            advanceSearch.DateStatus = "0";
        }
    }
    protected void btnDeptBack_Click(object sender, EventArgs e)
    {
    }
    protected void btnDeptSearch_Click(object sender, EventArgs e)
    {
        if (rbDepartmentMove.SelectedItem != null)
        {
            DepartmentProcureHistoryAdvanceSearch();
        }
        PopulateDepartmentMoveGrid();
    }
    protected void btnBack1_Click(object sender, EventArgs e)
    {
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
       // Session["UserManager_Control"] = "Purchase/ucPurchaseOrderRequest.ascx";
      //  Response.Redirect("BusinessProcessAutomation.aspx");
    }
    protected void rbDepartmentMove_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (rbDepartmentMove.SelectedItem.ToString() == "ProductCode")
        {
            txtDeptProductCode.Enabled = true;
            txtDeptProductName.Enabled = false;
            txtDeptProductName.Text = string.Empty;
            txtDeptMovedBy.Enabled = false;
            txtDeptMovedBy.Text = string.Empty;
            ddlSelect3.SelectedIndex = 0;
            txtDateOfCreation2.Text = string.Empty;
            txtDateOfCreation2.Enabled = false;
            txtDate2.Text = string.Empty;
            txtDate2.Enabled = false;
        }
        else if (rbDepartmentMove.SelectedItem.ToString() == "ProductName")
        {
            txtDeptProductCode.Enabled = false;
            txtDeptProductName.Enabled = true;
            txtDeptProductCode.Text = string.Empty;
            txtDeptMovedBy.Enabled = false;
            txtDeptMovedBy.Text = string.Empty;
            ddlSelect3.SelectedIndex = 0;
            txtDateOfCreation2.Text = string.Empty;
            txtDateOfCreation2.Enabled = false;
            txtDate2.Text = string.Empty;
            txtDate2.Enabled = false;
        }
        else if (rbDepartmentMove.SelectedItem.ToString() == "MovedBy")
        {
            txtDeptProductCode.Enabled = false;
            txtDeptProductName.Enabled = false;
            txtDeptProductCode.Text = string.Empty;
            txtDeptMovedBy.Enabled = true;
            txtDeptProductName.Text = string.Empty;
            ddlSelect3.SelectedIndex = 0;
            txtDateOfCreation2.Text = string.Empty;
            txtDateOfCreation2.Enabled = false;
            txtDate2.Text = string.Empty;
            txtDate2.Enabled = false;
        }
        else if (rbDepartmentMove.SelectedItem.ToString() == "Date")
        {
            txtDateOfCreation2.Enabled = true;
            ddlSelect3.Enabled = true;
            ImageButton5.Enabled = true; ;
            txtDate2.Text = string.Empty;
            txtDate2.Enabled = false;
            txtDeptMovedBy.Text = string.Empty;
            txtDeptMovedBy.Enabled = false;
            txtDeptProductCode.Text = string.Empty;
            txtDeptProductCode.Enabled = false;
            txtDeptProductName.Enabled = false;
            txtDeptProductName.Text = string.Empty;
            if (ddlSelect3.SelectedItem.ToString() == "Between")
            {
                ImageButton6.Enabled = true; ;
                txtDate2.Enabled = true;
            }
            else
            {
                ImageButton6.Enabled = false; ;
                txtDate2.Enabled = false;
            }
        }
        else
        {
            txtDeptProductName.Text = string.Empty;
            txtDeptProductCode.Enabled = false;
            txtDeptProductName.Enabled = false;
            txtDeptProductCode.Text = string.Empty;
            txtDeptMovedBy.Enabled = false;
            txtDeptMovedBy.Text = string.Empty;
            ddlSelect3.SelectedIndex = 0;
            txtDateOfCreation2.Text = string.Empty;
            txtDateOfCreation2.Enabled = false;
            txtDate2.Text = string.Empty;
            txtDate2.Enabled = false;
        }

    }
    protected void rbLocalPurchase_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (rbLocalPurchase.SelectedItem.ToString() == "Requester")
        {
            txtLocalPurchasRequester.Enabled = true;
            ddlAmountSelect.SelectedIndex = 0;
            ddlAmountSelect.Enabled = false;
            txtDateofCreation1.Text = string.Empty;
            txtDateofCreation1.Enabled = false;
            txtDate1.Text = string.Empty;
            txtDate1.Enabled = false;
            ddlSelect1.SelectedIndex = 0;
            txtAmount.Enabled = false;
            txtAmount.Text = string.Empty;

        }
        else if (rbLocalPurchase.SelectedItem.ToString() == "Amount")
        {
            txtLocalPurchasRequester.Text = string.Empty;
            txtLocalPurchasRequester.Enabled = false;
            ddlAmountSelect.Enabled = true;
            txtAmount.Enabled = true;
            txtDateofCreation1.Text = string.Empty;
            txtDateofCreation1.Enabled = false;
            txtDate1.Text = string.Empty;
            txtDate1.Enabled = false;
            ddlSelect1.SelectedIndex = 0;

        }
        else if (rbLocalPurchase.SelectedItem.ToString() == "Date")
        {
            txtDateofCreation1.Enabled = true;
            ddlSelect1.Enabled = true;
            ImageButton3.Enabled = true; ;
            txtDate1.Text = string.Empty;
            txtDate1.Enabled = false;
            txtLocalPurchasRequester.Text = string.Empty;
            txtLocalPurchasRequester.Enabled = false;
            txtDate1.Text = string.Empty;
            txtDate1.Enabled = false;
            ddlAmountSelect.SelectedIndex = 0;
            ddlAmountSelect.Enabled = false;
            txtAmount.Text = string.Empty;
            txtAmount.Enabled = false;

            if (ddlSelect1.SelectedItem.ToString() == "Between")
            {
                ImageButton4.Enabled = true; ;
                txtDate1.Enabled = true;
            }
            else
            {
                ImageButton4.Enabled = false; ;
                txtDate1.Enabled = false;
            }
        }
        else
        {
            ddlAmountSelect.SelectedIndex = 0;
            txtLocalPurchasRequester.Text = string.Empty;
            txtLocalPurchasRequester.Enabled = false;
            ddlAmountSelect.Enabled = false;
            txtAmount.Enabled = false;
            txtDateofCreation1.Text = string.Empty;
            txtDateofCreation1.Enabled = false;
            txtDate1.Text = string.Empty;
            txtDate1.Enabled = false;
            ddlSelect1.SelectedIndex = 0;
            txtAmount.Text = string.Empty;

        }
    }
    protected void rblCriteria_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (rblCriteria.SelectedItem.ToString() == "PurchaseOrderID")
        {
            txtPurchaseOrderID.Enabled = true;
            txtDateOfCreation.Text = string.Empty;
            ddlSelect.SelectedIndex = 0;
            txtDate.Text = string.Empty;
            txtProductName.Text = string.Empty;
            txtProductName.Enabled = false;
            txtDate.Enabled = false;
            txtDateOfCreation.Enabled = false;
            ddlSelect.Enabled = false;
            advanceSearch.PurchaseOrderID = txtPurchaseOrderID.Text.Trim();
            advanceSearch.DateofCreation = string.Empty;
            advanceSearch.ProductName = string.Empty;
            advanceSearch.DateofCreation1 = string.Empty;
            advanceSearch.DateStatus = "0";

        }

        else if (rblCriteria.SelectedItem.ToString() == "ProductName")
        {
            txtProductName.Enabled = true;
            txtPurchaseOrderID.Text = string.Empty;
            txtDate.Text = string.Empty;
            txtDateOfCreation.Text = string.Empty;
            txtDate.Enabled = false;
            txtDateOfCreation.Enabled = false;
            ddlSelect.Enabled = false;
            txtPurchaseOrderID.Enabled = false;
            ddlSelect.SelectedIndex = 0;
            advanceSearch.PurchaseOrderID = string.Empty;
            advanceSearch.DateofCreation = string.Empty;
            advanceSearch.ProductName = txtProductName.Text.Trim();
            advanceSearch.DateofCreation1 = string.Empty;
            advanceSearch.DateStatus = "0";
        }
        else if(rblCriteria.SelectedItem.ToString() == "Date")
        {
            txtPurchaseOrderID.Text = string.Empty;
            txtProductName.Text = string.Empty;
            txtProductName.Enabled = false;
            ImageButton1.Enabled = true; ;
            ddlSelect.Enabled = true;
            txtDateOfCreation.Enabled = true;
            txtProductName.Enabled = false;
            txtPurchaseOrderID.Enabled = false;
            if (ddlSelect.SelectedItem.ToString() == "Between")
            {
                ImageButton2.Enabled = true; ;
                txtDate.Enabled = true;
                advanceSearch.DateofCreation = txtDateOfCreation.Text.Trim();
                advanceSearch.DateofCreation1 = txtDate.Text.Trim();
                advanceSearch.PurchaseOrderID = string.Empty;
                advanceSearch.ProductName = string.Empty;
                if (ddlSelect.SelectedIndex != 0)
                    advanceSearch.DateStatus = ddlSelect.SelectedItem.ToString();
                else
                    advanceSearch.DateStatus = "0";
            }
            else
            {

                advanceSearch.DateofCreation = txtDateOfCreation.Text.Trim();
                advanceSearch.PurchaseOrderID = string.Empty;
                advanceSearch.ProductName = string.Empty;
                if (ddlSelect.SelectedIndex != 0)
                    advanceSearch.DateStatus = ddlSelect.SelectedItem.ToString();
                else
                    advanceSearch.DateStatus = "0";
            }
        }
        else
        {
            txtDate.Enabled = false;
            txtDateOfCreation.Text = string.Empty;
            txtProductName.Text = string.Empty;
            txtPurchaseOrderID.Text = string.Empty;
            txtDateOfCreation.Enabled = false;
            txtProductName.Enabled = false;
            txtPurchaseOrderID.Enabled = false;
            advanceSearch.ProductName = string.Empty;
            advanceSearch.DateofCreation = string.Empty;
            advanceSearch.PurchaseOrderID = string.Empty;
            advanceSearch.DateStatus = "0";
        }
      
    }
}
